<?php
/**
 * Enter description here ...
 * @author NgoAnhTu
 * @date 2013-10-19
 */
final class AlbumDetailDAO extends DAO {
	
	private static $instance = null;
	
	/**
	 * AlbumDetailDAO instance only
	 * @return AlbumDetailDAO
	 */
	public static function getInstance() {
		if (self::$instance == null)
			self::$instance = new AlbumDetailDAO("AlbumDetail");
		return self::$instance;
	}
	
	/**
	 * Enter description here ...
	 * @param integer $albumId
	 * @param string $code
	 */
	public function getContent($albumId, $code) {
		$detail = $this->getDetail($albumId, $code);
		if ($detail != null) {
			return $detail->content;
		}
		return null;
	}
	
	/**
	 * Enter description here ...
	 * @param integer $albumId
	 * @param string $code
	 */
	public function getDetail($albumId, $code) {
		$details = $this->select(DAO::FIRST_PAGE, DAO::FIRST_PAGE, "ReferenceID=$albumId AND LanguageCode='$code'");
		if (sizeof($details) > 0) {
			return $details[0];
		}
		return null;
	}

	/**
	 * Enter description here ...
	 * @param integer $albumId
	 */
	public function getDetails($albumId) {
		return $this->select(DAO::FIRST_PAGE, DAO::MAX_SIZE, "ReferenceID=$albumId", "LanguageCode", DAO::DESC);
	}
	
	/**
	 * Enter description here ...
	 * @param AlbumDetail $detail
	 */
	public function delete($detail) {
		$sql = DAO::SQL_DELETE;
		$this->addTable($sql);
		$this->addCondition($sql, 'ID=' . $detail->id);
		return mysql_query($sql);
	}
}
?>